/**
 * 应用基础视图
 */
define(['jquery', 'underscore', 'RootView'],
    function ($, _, RootView) {
        var MainView = RootView.extend({
            el: 'body',
            events: {
                'click                                     .read-change': 'changeNoticeToRead'
            },
            initialize: function () {
            },
            //#  改变阅读状态
            //
            changeNoticeToRead: function (event) {
                event.preventDefault();
                var $target = $(event.target).closest('.read-change'),
                    $targetItem = $target.closest('li'),
                    url = $target.data('url'),
                    that = this;
                if (!$targetItem.hasClass('read')) {
                    $.ajax({
                        url: url,
                        type: 'post',
                        dataType: 'json',
                        beforeSend: function (req) {
                            req.setRequestHeader("Accept", "application/json");
                        },
                    }).done(function (res) {
                        if (res.Errors && !res.Errors.IsValid) {
                            that.errorAlert(res.Errors.ErrorItems[0].ErrorMessage);
                        } else {
                            $targetItem.addClass('read');
                        }
                    }).fail(function () {
                        that.errorAlert('网络加载超时');
                    }).always(function () {
                    });
                } else {
                    return;
                }
            },

        });
        return MainView;
    });
